<template>
  <div style="margin-top: 20px;">
    <el-card class="box-card21">
      <div class="clearfix">
        <span style="font-size: 1.5em; font-weight: bold; margin-left: 10px;">{{ from[0].topic }}</span>
        <div style="float: right;">
          <el-button type="primary" size="small">采购</el-button>
          <el-button type="danger" size="small" style="margin-left: 10px;">导入</el-button>
          <el-button type="danger" size="small" style="margin-left: 10px;">导出</el-button>
        </div>
      </div>
      <div class="status" style="float: right; margin-right: 20px;">
        <svg-icon icon-class="daicai" style="width: 110px; height: 100px;" />
      </div>
      <div style="margin-top: 40px;">
        <div style="margin-left: 10px;">申请人：{{ from[0].applicant }}</div>
        <div style="margin-top:-20px ;margin-left: 290px;">申请时间：{{ from[0].date }}</div>
      </div>
      <el-tabs style="margin-top: 50px;">
        <el-tab-pane label="采购信息">
          <el-card>
            <div slot="header" class="clearfix">
              <span>基本信息</span>
            </div>
            <el-row :gutter="20" style="line-height: 3; margin-left: 90px; margin-right: -230px;">
              <el-col :span="12">
                <div>申请单号：{{ from[0].code }}</div>
                <div>申请日期：{{ from[0].date }}</div>
                <div>申请部门：{{ from[0].department }}</div>
                <div>申请事由：{{ from[0].affair }}</div>
                <div>备注：{{ from[0].remark }}</div>
              </el-col>
              <el-col :span="12">
                <div>申请主题：{{ from[0].topic }}</div>
                <div>申请人：{{ from[0].applicant }}</div>
                <div>联系方式：{{ from[0].contact }}</div>
              </el-col>
            </el-row>
          </el-card>
          <!--关联文件-->
          <el-card style="margin-top: 20px;">
            <div slot="header" class="clearfix">
              <span>关联文档</span>
              <el-button style="float: right;" type="primary" size="small">批量下载</el-button>
            </div>
            <el-table :data="tableData2" style="width: 100%">
              <el-table-column type="selection" width="55" align="center"></el-table-column>
              <el-table-column prop="id" label="序号" width="55" align="center">
                <template v-slot="scope">
                  {{ scope.$index + 1 }}
                </template>
              </el-table-column>
              <el-table-column prop="filename" label="文件名" align="center"></el-table-column>
              <el-table-column prop="uploadTime" label="上传时间" align="center"></el-table-column>
              <el-table-column prop="uploader" label="上传者" align="center"></el-table-column>
              <el-table-column prop="size" label="文档大小" align="center"></el-table-column>
              <el-table-column label="操作" width="80" align="center">
                <template slot-scope="scope">
                  <el-button type="text" size="small" @click="downloadFile(scope.row)">下载</el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-card>
          <div style="height: 100px;"></div>
        </el-tab-pane>
        <el-tab-pane label="采购明细">
          <el-card>
            <div slot="header" class="clearfix">
              <span>采购明细</span>
            </div>
            <div>
              <el-button>导出</el-button>
              <el-table :data="tableData" style="width: 100%; margin-top: 20px">
                <el-table-column type="selection" width="55" align="center"></el-table-column>
                <el-table-column prop="id" label="序号" width="60" align="center">
                  <template v-slot="scope">
                    {{ scope.$index + 1 }}
                  </template>
                </el-table-column>
                <el-table-column prop="numbering" label="设备编号" align="center" width="200"></el-table-column>
                <el-table-column prop="name" label="设备名称" align="center" width="150"></el-table-column>
                <el-table-column prop="model" label="规格型号" align="center" width="150"></el-table-column>
                <el-table-column prop="type" label="设备类型" align="center" width="150"></el-table-column>
                <el-table-column prop="brand" label="品牌" align="center" width="150"></el-table-column>
                <el-table-column prop="quantity" label="申请采购数量" align="center" width="150"></el-table-column>
                <el-table-column prop="reference" label="参考单价" align="center" width="150"></el-table-column>
                <el-table-column prop="estimate" label="预计总金额" align="center" width="150"></el-table-column>
                <el-table-column prop="remark" label="备注" align="center" width="150"></el-table-column>
              </el-table>

              <div class="summary">
                总数量：<b>{{ totalQuantity }}</b>
                总金额：<b style="color: red">{{ totalAmount.toFixed(2) }}</b>
              </div>
            </div>
          </el-card>
        </el-tab-pane>
        <el-tab-pane label="采购记录">
          <el-card>
            <div slot="header" class="clearfix">
              <span>采购记录</span>
            </div>
            <div>
              <el-button style="margin-bottom: 10px">导出</el-button>
              <el-table :data="tableData3" style="width: 100%">
                <el-table-column type="selection" width="55" align="center" fixed></el-table-column>
                <el-table-column prop="id" label="序号" width="60" align="center" fixed>
                  <template v-slot="scope">
                    {{ scope.$index + 1 }}
                  </template>
                </el-table-column>
                <el-table-column label="操作" width="80" align="center" fixed>
                  <template slot-scope="scope">
                    <el-link type="primary" @click="handleView(scope.row)">查看</el-link>
                  </template>
                </el-table-column>
                <el-table-column prop="code" label="采购单号" align="center" width="150"></el-table-column>
                <el-table-column prop="topic" label="采购主题" align="center" width="150"></el-table-column>
                <el-table-column prop="date" label="采购日期" align="center" width="150"></el-table-column>
                <el-table-column prop="applicant" label="采购人员" align="center" width="150"></el-table-column>
                <el-table-column prop="department" label="采购部门" align="center" width="150"></el-table-column>
                <el-table-column prop="contact" label="联系方式" align="center" width="150"></el-table-column>
                <el-table-column prop="supplier" label="供应商" align="center" width="150"></el-table-column>
                <el-table-column prop="supplier" label="联系人" align="center" width="150"></el-table-column>
                <el-table-column prop="supplier" label="联系方式" align="center" width="150"></el-table-column>
                <el-table-column prop="supplier" label="采购数量" align="center" width="150"></el-table-column>
                <el-table-column prop="supplier" label="采购总金额" align="center" width="150"></el-table-column>
              </el-table>
            </div>
          </el-card>
        </el-tab-pane>
        <el-tab-pane label="审核记录">
          <el-card>
            <div slot="header" class="clearfix">
              <span>审核记录</span>
            </div>
            <div>
              <el-button style="margin-bottom: 10px;">导出</el-button>
              <el-table :data="tableData4" style="width: 100%">
                <el-table-column type="selection" width="55" align="center"></el-table-column>
                <el-table-column prop="index" label="序号" width="60" align="center">
                  <template v-slot="scope">
                    {{ scope.$index + 1 }}
                  </template>
                </el-table-column>
                <el-table-column prop="step" label="操作节点" align="center"></el-table-column>
                <el-table-column prop="operator" label="操作人" align="center"></el-table-column>
                <el-table-column prop="action" label="操作" align="center"></el-table-column>
                <el-table-column prop="time" label="操作时间" align="center"></el-table-column>
                <el-table-column prop="content" label="审批内容" align="center"></el-table-column>
              </el-table>
            </div>
          </el-card>
        </el-tab-pane>
        <el-tab-pane label="操作记录">
          <el-card>
            <div slot="header" class="clearfix">
              <span>采购记录</span>
            </div>
            <div>
              <el-button style="margin-bottom: 10px;">导出</el-button>
              <el-table :data="tableData5" style="width: 100%">
                <el-table-column type="selection" width="55"></el-table-column>
                <el-table-column prop="index" label="序号" width="60" align="center">
                  <template v-slot="scope">
                    {{ scope.$index + 1 }}
                  </template>
                </el-table-column>
                <el-table-column prop="operator" label="操作人" align="center"></el-table-column>
                <el-table-column prop="time" label="操作时间" align="center"></el-table-column>
                <el-table-column prop="content" label="操作内容" align="center"></el-table-column>
              </el-table>
              <el-pagination background layout="prev, pager, next, sizes, total" :total="45" :page-size="10"
                style="margin-top: 20px; text-align: right">
              </el-pagination>
            </div>
          </el-card>
        </el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>

<script>
import {
  SelectAll
} from "@/api/eastjet-maintenance/caig/cai";
export default {
  data() {
    return {
      //基本信息
      from: [],
      //操作记录
      tableData5: [
        { index: 1, operator: 'admin', time: '2026-06-07 20:00:00', content: '' },
        { index: 2, operator: 'admin', time: '2026-06-07 20:00:00', content: '' },
        { index: 3, operator: 'admin', time: '2026-06-07 20:00:00', content: '' },
        { index: 4, operator: 'admin', time: '2026-06-07 20:00:00', content: '' },
        { index: 5, operator: 'admin', time: '2026-06-07 20:00:00', content: '' },
      ],
      //审核记录
      tableData4: [
        { index: 1, step: '提交节点', operator: '乾颐雅', action: '提交', time: '2022-07-12 10:04:39', content: '-' },
        { index: 2, step: '仓库管理员', operator: '谢文茜', action: '通过', time: '2022-07-12 12:20:12', content: '领用原因核实无误，符合要求，批准申请。' },
        { index: 3, step: '部门经理', operator: '萧文惠', action: '通过', time: '2022-07-13 10:04:39', content: '领用符合公司管理规定和流程，批准。' },
      ],
      //采购记录
      tableData3: [],
      //采购明细
      tableData: [],
      //关联文件
      tableData2: []
    }
  },
  computed: {
    totalQuantity() {
      return this.tableData.reduce((sum, item) => sum + item.quantity, 0);
    },
    totalAmount() {
      return this.tableData.reduce((sum, item) => sum + item.estimate, 0);
    },
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      var map = { "code": this.$route.query.code, "username": this.$store.state.user.name, pan: "1" }
      SelectAll(map).then((res) => {
        this.from = res.data.data.list;
        this.tableData = res.data.data.purchasedetails;
        this.tableData2 = res.data.data.docun;
        this.tableData3 = res.data.data.list2;
      })
    },
    handleView(row) {
      var map = { "code": row.code, "username": this.$store.state.user.name, pan: "1" }
      SelectAll(map).then((res) => {
        this.from = res.data.data.list;
        this.tableData = res.data.data.purchasedetails;
        this.tableData2 = res.data.data.docun;
        this.tableData3 = res.data.data.list2;
      })
    },
  }
};

</script>

<style scoped>
.box-card21 {
  width: 1254px;
  /* height: 4010px; */
  margin-left: 30px;
}

.summary {
  margin-top: 10px;
  text-align: right;
}
</style>
